package com.udesc.larva.delta.files;

import javax.swing.filechooser.FileFilter;
import java.io.*;

public class FiltroDeExtensao extends FileFilter {

    private String ext  = "";
    private String desc = "";

    public FiltroDeExtensao(String ext, String description) {

        this.ext = new String(ext);
        this.desc = java.text.MessageFormat.format("{0} (*.{1})", new String[]{ description, ext });
    }
    
    public File applyExtension(File original) {
        return new File(original.getParentFile(), original.getName().concat(".".concat(ext)));
    }
    
    public boolean accept(File f) {

        if (f.canRead() || f.canWrite())
            return (f.getName().endsWith("." + ext) || f.isDirectory() || (f.isDirectory() && f.isHidden() && f.getName().startsWith(".")));
        return false;
    }
    
    public String getDescription() {
           return desc;
    }
}